package com.test;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/hello-world")
public class HelloWorldController {

	@RequestMapping(value = "/hello")
	@ResponseBody
	public ModelAndView hello(
			@RequestParam(value = "name", required = false, defaultValue = "Maven SpringMVC") String name) {
		// 指定视图
		ModelAndView modelAndView = new ModelAndView("hello-world");
		// 向视图中添加数据，供页面展示
		modelAndView.addObject("message", "Hello world! My Name Is ");
		modelAndView.addObject("name", name);
		return modelAndView;
	}
}
